#ifndef __LOG
#define __LOG

#include <iostream>
#include <fstream>
#include <time.h>
#include <windows.h>

using namespace std;

class Log
{
private:
	char m_path[1024];
	char m_fullname[1024];
	int m_level;
	ofstream m_outfile;
	char m_dateStr[9];
    char m_timeStr[9];
	CRITICAL_SECTION m_cs;
	char m_message[1024];

	bool openfile()
	{
		_strdate(m_dateStr);
		strcpy(m_dateStr, "testlog");
		sprintf(m_fullname, "%s\\%s.log", m_path, m_dateStr);
		m_outfile.open(m_fullname, ios::app);
		return true;
	}

public:
	Log() 
	{
		InitializeCriticalSection(&m_cs);
		strcpy(m_path,"c:\\");
		openfile();
		m_level = 2;
	}

	~Log()
	{
		TRACE(5, "Log destructor called\n");
	}

	bool TRACE(int level, char * msg)
	{
		if (level >= m_level)
		{
			_strtime(m_timeStr);
			sprintf(m_message, "%s: %s", m_timeStr, msg);
			m_outfile << m_message;
			m_outfile.flush();
			cout << m_message;
		}
		return true;
	}
};

#endif